import * as Immutable from 'seamless-immutable';
import { Action } from 'redux-actions';
import { OperaType } from './const';

export const ActionName = {
  /** 改变操作模式 */
  changeOperaType: 'changeOperaType',
  /** 新增节点 */
  createNode: 'createNode',
  /** 执行新增节点 */
  doCreateNode: 'doCreateNode',
  /** 清除新增节点标记 */
  clearCreateNodeData: 'clearCreateNodeData',
};


export default function (
  state = Immutable.from({
    operaType: OperaType.Drag
  }),
  action: Action<any>
) {
  const { type, payload } = action;

  switch (type) {
    case ActionName.changeOperaType:
      return state.merge({ operaType: payload.operaType });
    case ActionName.createNode:
      return state.merge({ createNodeData: payload.createNodeData });
    case ActionName.doCreateNode:
      return state.merge({ doCreateNodeData: payload.createNodeData });
    case ActionName.clearCreateNodeData:
      return state.merge({ doCreateNodeData: null });
    default:
      return state;
  }
}

